<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <%@ include file="/common/plateform/include/common-base.jsp"%>	
  <title>审计模型管理</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
</head>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">
  <!-- top start -->
  <%@include file="/common/plateform/top.jsp" %>
  <!-- top end -->
  <!-- left start -->
  <%@include file="/common/plateform/left.jsp" %>
  <!-- left end-->
  <div class="content-wrapper">
  		
    <!-- Main start -->
<section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box">
           <div class="box-header">
              			<center>
              				<div class="btn-group">
								<button class="btn btn-info" type="button" onclick="toAdd('my_modal_model','','addModelForm');">增加</button>
				            	<button class="btn btn-info" type="button" onclick="refresh();">刷新</button>
			            	</div>					
            	</center>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
            <center>
				<form id="searchFrom" class="form-horizontal">
				<input type="hidden" name="doCode" value="logModelList"/>
				</form>
				</center>
            
              <table id="example" class="table table-bordered table-hover" >
                <thead>
                <tr>
                  <th>名称</th>
                  <th>英文全名称</th>
                  <th>业务名称</th>
                  <th>系统名称</th>
                  <th>描述</th>
                  <th>操作</th>
                </tr>
                </thead>
                <tbody id="myList">
                </tbody>
              </table>
         	    <center>
    	  			  <ul id="pageList"></ul>
        		</center>
            </div>
          </div>
          
          
        </div>
      </div>
    </section>
    <!-- Main end -->
    
  <div class="modal fade" id="my_modal_model" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:900px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title">
							<font color="red">信息添加/修改</font>&nbsp;
						</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" role="form" id="addModelForm">
							<input type="hidden" name="doCode" value="logExecute"/>
							<input type="hidden" name="exeType" value="">
							<input type="hidden" data-name="model.modelId" name="modelId"  value=""/>
							<input type="hidden" id="formToken" name="formToken"  value="${formToken}">
					        <div class="box-body" id="submitFormData">
					          <!-- Custom Tabs -->
					          <div class="nav-tabs-custom">
					            <div class="tab-content">
					              <div class="tab-pane active" id="tab_1">
					                <div class="form-group">
					                  <label for="inputCateCname" class="col-sm-2 control-label" >中文名称<font color="red">*</font></label>
					                  <div class="col-sm-8">
					                    <input type="text" id="modelCname" class="form-control clean" name="modelCname" data-name="model.modelCname" required placeholder="必填项" >
					                  </div>
					                </div>
					                <div class="form-group">
					                  <label class="col-sm-2 control-label" >英文名称<font color="red">*</font></label>
					                  <div class="col-sm-10">
					                    <input type="text" id="modelEname" class="form-control clean" name="modelEname" data-name="model.modelEname" required placeholder="必填项">
					                  </div>
					                </div>
					                <div class="form-group">
					                  <label class="col-sm-2 control-label" >业务名称<font color="red">*</font></label>
					                  <div class="col-sm-10">
					                  	<input type="text" id="modelBussiness" class="form-control clean" name="modelBussiness" data-name="model.modelBussiness" required placeholder="必填项">
					                  </div>
					                </div>
					                <div class="form-group">
					                  <label class="col-sm-2 control-label" >系统名称<font color="red">*</font></label>
					                  <div class="col-sm-10">
					                  	<input type="text" id="modelSysname" class="form-control clean" name="modelSysname" data-name="model.modelSysname" required placeholder="必填项">
					                  </div>
					                </div>
					                
					                <div class="form-group">
					                  <label class="col-sm-2 control-label" >业务描述</label>
					                  <div class="col-sm-10">
					                  	<textarea id="modelRemark" class="form-control clean" name="modelRemark" data-name="model.modelRemark" rows="3" cols="50"></textarea>
					                  </div>
					                </div>
					              </div>					             
					              <!-- /.tab-pane -->
					            </div>
					            <!-- /.tab-content -->
					          </div>
					          <!-- nav-tabs-custom -->
					        </div>
			                <div class="box-footer">
				                <button type="button" class="btn btn-success pull-left" onclick="cannel('my_modal_model');">取消</button>
				                <button type="button" class="btn btn-danger pull-right" onclick="save('addModelForm');">提 交</button>
				            </div>
						</form>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>		
</div>  

<div class="modal fade" id="my_modal_modelDetail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:900px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title"><font color="red">属性添加/修改</font>&nbsp;</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" role="form" id="addModelDetailForm">
							<input type="hidden" name="doCode" value="logExecute"/>
							<input type="hidden" name="exeType" value="">
							<input type="hidden" data-name="detail.modelId" name="modelId"  value=""/>
							<input type="hidden" data-name="detail.detailId" name="detailId"  value=""/>
							<input type="hidden" id="formToken" name="formToken"  value="${formToken}">
					        <div class="box-body" id="submitFormData">
					          <!-- Custom Tabs -->
					          <div class="nav-tabs-custom">
					            <div class="tab-content">
					              <div class="tab-pane active" id="tab_1">
					                <div class="form-group">
					                  <label for="inputCateCname" class="col-sm-2 control-label" >中文名称<font color="red">*</font></label>
					                  <div class="col-sm-8">
					                    <input type="text" id="columnCname" class="form-control clean" name="columnCname" data-name="detail.columnCname" required placeholder="必填项" >
					                  </div>
					                </div>
					                <div class="form-group">
					                  <label class="col-sm-2 control-label" >英文名称<font color="red">*</font></label>
					                  <div class="col-sm-8">
					                    <input type="text" id="columnEname" class="form-control clean" name="columnEname" data-name="detail.columnEname" required placeholder="必填项">
					                  </div>
					                </div>
					                <div class="form-group">
					                  <label class="col-sm-2 control-label" >是否主键<font color="red">*</font></label>
					                  <div class="col-sm-8">
					                  	<input type="radio" name="primaryKey" value="1" />是<input type="radio" name="primaryKey" value="0" checked />否
					                  </div>
					                </div>
					              </div>					             
					              <!-- /.tab-pane -->
					            </div>
					            <!-- /.tab-content -->
					          </div>
					          <!-- nav-tabs-custom -->
					        </div>
			                <div class="box-footer">
				                <button type="button" class="btn btn-success pull-left" onclick="cannel('my_modal_modelDetail');">取消</button>
				                <button type="button" class="btn btn-danger pull-right" onclick="save('addModelDetailForm');">提 交</button>
				            </div>
						</form>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>		
</div>  

<div class="modal fade" id="my_modal_detailList" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:900px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title"><font color="red">属性列表</font>&nbsp;</h4>
					</div>
					<div class="modal-body">
					<center>
              				<div class="btn-group">
								<button class="btn btn-info" type="button" onclick="toAdd('my_modal_modelDetail','','addModelDetailForm');">增加</button>
			            	</div>					
            	     </center>
						<form class="form-horizontal" role="form" id="searchModelDetailForm">
							<input type="hidden" name="doCode" value="logExecute"/>
							<input type="hidden" name="exeType" value="modelDetailList">
							<input type="hidden" name="modelId"  value=""/>
						</form>
						<table id="example_detail" class="table table-bordered table-hover" >
			                <thead>
			                <tr>
			                  <th>属性名称</th>
			                  <th>属性英文名称</th>
			                  <th>是否主键</th>
			                  <th>操作</th>
			                </tr>
			                </thead>
			                <tbody id="myDetailList">
			                </tbody>
			              </table>
			         	    <center>
			    	  			  <ul id="pageDetailList"></ul>
			        		</center>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>		
</div>  
    
    
    <script type="text/template" id="dataModelList">
	  		<? for ( var i = 0; i < rows.length; i++) {?>
				<tr>
					<td style="display:none;"><?=rows[i].modelId?></td>
					<td><?=rows[i].modelCname?></td>
					<td><?=rows[i].modelEname?></td>
					<td><?=rows[i].modelBussiness?></td>
					<td><?=rows[i].modelSysname?></td>
					<td><?=rows[i].modelRemark?></td>
                    <td>
                    <a href="javascript:void('0')" onclick="toAdd('my_modal_model','<?=rows[i].modelId?>','addModelForm')" class="btn btn-info">修改</a>
                    <a href="javascript:void('0')" onclick="del('<?=rows[i].modelId?>','delModel')" class="btn btn-info">删除</a>
                    <a href="javascript:void('0')" onclick="getTableDetailData('<?=rows[i].modelId?>')" class="btn btn-info">属性列表</a>
                    </td>
				</tr>
     		<?}?>
	</script>
	<script type="text/template" id="dataDetailList">
	  		<? for ( var i = 0; i < rows.length; i++) {?>
				<tr>
					<td><?=rows[i].columnCname?></td>
					<td><?=rows[i].columnEname?></td>
					<td><?if(rows[i].primaryKey=='1'){?>是<?}else{?>否<?}?></td>
                    <td>
                    <a href="javascript:void('0')" onclick="toAdd('my_modal_modelDetail','<?=rows[i].detailId?>','addModelDetailForm')" class="btn btn-info">修改</a>
                    <a href="javascript:void('0')" onclick="del('<?=rows[i].detailId?>','delModelDetail')" class="btn btn-info">删除</a>
                    </td>
				</tr>
        <?}?>
	</script>

<script>
var clickMenu= 'log-model-list';
var id;
$(function () {
	getTableDatas();
  });
  

function cleanData(id){
	$(':input','#'+id)  
	 .not(':button, :submit, :reset, :hidden')  
	 .val('')  
	 //.removeAttr('checked')  
	 .removeAttr('selected'); 
}

function getTableDatas(){
	deleteAllRow('example');
	var utrlss="${ctx}/trans/list/logModelList";
	$.ajax({
		   type:'get',
		   url:utrlss,//user_search_url,
		   data:$('#searchFrom').serialize()+getCurrentPage(utrlss+'?'+$('#searchFrom').serialize(),10),
		   dataType:'json',
		   success: function(myData){
			   console.log(myData);
			if("T"==myData.flag){
				var data = baidu.template('dataModelList',eval(myData));  
				$("#myList").html(data);
				  var option= {
						   ele:$("#pageList")[0],
						   total:myData.total,
						   fn:getTableDatas,
						   url:utrlss+"?"+$('#searchFrom').serialize()
					   }
				generatePages(option);
			}
		   }
		});	
  }
  
function getTableDetailData(modelId){
	$('#my_modal_detailList').modal('show');
	id=modelId;
	deleteAllRow('example_detail');
	$("#searchModelDetailForm").find("input[name='modelId']").val(id);
	var utrlss="${ctx}/trans/info/";
	$.ajax({
		   type:'get',
		   url:utrlss,//user_search_url,
		   data:$('#searchModelDetailForm').serialize()+getCurrentPage(utrlss+"?"+$('#searchModelDetailForm').serialize(),10),
		   dataType:'json',
		   success: function(myData){
			   console.log(myData);
		  if("T"==myData.flag){
			var data = baidu.template('dataDetailList',eval(myData));  
			$("#myDetailList").html(data);
			  var option= {
					   ele:$("#pageDetailList")[0],
					   total:myData.total,
					   fn:refresh2,
					   url:utrlss+"?"+$('#searchModelDetailForm').serialize()
				   }
			generatePages(option);
			  }
		   }
		});	
  }

function deleteAllRow(tableId){
	var tb = document.getElementById(tableId);
	if(tb){
	     var rowNum=tb.rows.length;
	     for (var i=1;i<rowNum;i++){
	         tb.deleteRow(i);
	         rowNum=rowNum-1;
	         i=i-1;
	     }
     }
}

function del(modelId,exeType){
	var data={'modelId':modelId,exeType:exeType,doCode:'logExecute'};
	if(exeType=='delModelDetail'){
		data={'detailId':modelId,exeType:exeType,doCode:'logExecute'};
	}
	layer.confirm('您确定要删除该此信息？', {
		  btn: ['确定','取消'] //按钮
		}, function(){
			$.ajax({
			    type:'post',
			    url:ctx+'/trans/submit/',
			    data:data,
			    dataType:'json',
			    success: function(myData){
			    	if(myData.flag=='T'){
			    		if(exeType=='delModelDetail'){
			    			refresh2();
			    		}else{
			    		   refresh();
			    		}
			    	}else{
			    		layer.alert('删除失败', {skin: 'layui-layer-molv',closeBtn: 0});
			    	}
			  	}
			});	
		});
}

function cannel(modalId){
	$('#'+modalId).modal('hide');
	if("my_modal_modelDetail"==modalId){
		refresh2();
	}
}
function toAdd(divId,modelId,formId){
	$('#'+divId).modal('show');
	if("addModelDetailForm"==formId){
		$('#my_modal_detailList').modal('hide');
		$("#"+formId).find("input[name='exeType']").val("saveModelDetail");
	}else{
	    $("#"+formId).find("input[name='exeType']").val("saveModel");
	}
	if(modelId){
		if("addModelDetailForm"==formId){
			$("#"+formId).find("input[name='modelId']").val(id);
			$("#"+formId).find("input[name='detailId']").val(modelId);
		}else{
	        $("#"+formId).find("input[name='modelId']").val(modelId);
		}
	    $('#'+formId).find(".clean").val("");//按照样式清空；
	    toEditModel(modelId,formId);
	}else{
		$('#'+formId).find(".clean").val("");//按照样式清空；
		$("#"+formId).find("input[name='modelId']").val('');
		if("addModelDetailForm"==formId){
			$("#"+formId).find("input[name='modelId']").val(id);
			$("#"+formId).find("input[name='detailId']").val("");
		}else{
	        $("#"+formId).find("input[name='modelId']").val("");
		}
	}
}
//DictUtil.checkRadioDict("trpPub.bBuyerExchange", myData.trpPub.bBuyerExchange);

function toEditModel(modelId,formId){
	var data={doCode:'logExecute',modelId:modelId,exeType:'modelEntity'};
	if(formId=='addModelDetailForm'){
		data={doCode:'logExecute',detailId:modelId,exeType:'modelDetailEntity'};
	}
	console.log(data);
	$.ajax({
	    type:'get',
	    url:ctx+'/trans/info/',
	    data:data,
	    dataType:'json',
	    success: function(myData){
	    	console.log(myData);
	    	if("addModelDetailForm"==formId){
	    	   FormUtil.loadView("detail", myData);
	    	   DictUtil.checkRadioDict("primaryKey", myData.primaryKey);
	    	}else{
	    		FormUtil.loadView("model", myData);
	    	}
	  	}
	});	
}

function save(formId){
	$.ajax({
	    type:'post',
	    url:ctx+'/trans/submit/',
	    data:$('#'+formId).serialize(),
	    dataType:'json',
	    success: function(myData){
	    	if(myData.flag=='T'){
	    		layer.alert('保存成功', {
	    		    skin: 'layui-layer-molv'
	    		    ,closeBtn: 0
	    		  });
	    		if("addModelDetailForm"==formId){
	    			refresh2();
	    		}else{
	    		   refresh();
	    		}
	    	}
	  	}
	});	
}

function refresh(){
    //window.location.reload();
	getTableDatas();
}

function refresh2(){
	getTableDetailData(id);
}
</script>
  </div>
  <!-- /.content-wrapper -->

  <!-- foot start -->
       
 <%@include file="/common/plateform/foot.jsp" %>
</div>    
</body>
	
</html>
